package thread;

public class Demo2 {
    static long count = 0;
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            for (long i = 0; i < 1_0000; i++) {
                count++;
            }
        });
        Thread t2 = new Thread(() -> {
            for (long i = 0; i < 1_0000; i++) {
                count++;
            }
        });
        // 开始计时
        long beg = System.currentTimeMillis();
        t1.start();
        t2.start();

        try {
            t1.join();
            t2.join(); // 此处的 join 就是让当前的 main 线程来等待 t 线程执行结束（等待 t 的 run 执行完）
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // 结束计时
        long end = System.currentTimeMillis();
        System.out.println("执行时间：" + (end - beg) + "ms");
    }
}
